//
//  BarButtonItem+Extension.swift
//  simpleWeibo
//
//  Created by 孙林 on 2017/9/10.
//  Copyright © 2017年 孙林. All rights reserved.
//

import UIKit


extension UIBarButtonItem {
    
    
    /// 创建自定义UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize 默认16号
    ///   - target: target
    ///   - action: action
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject ,action: Selector, isBack: Bool) {
        let custonBarButtonItem: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack == true {
            let imageName = "navigationbar_back_withtext"
            custonBarButtonItem.setImage(UIImage.init(named: imageName), for: .normal)
            custonBarButtonItem.setImage(UIImage.init(named: imageName + "_highlighted"), for: .highlighted)
        }
        custonBarButtonItem.sizeToFit()
        custonBarButtonItem.addTarget(target, action: action, for: .touchUpInside)
        
        self.init(customView: custonBarButtonItem)
    }
    
}
